package com.shanshan.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.shanshan.system.entity.MeetingSummary;
import com.shanshan.system.entity.Notice;
import com.shanshan.system.mapper.MeetingSummaryMapper;
import com.shanshan.system.service.IMeetingSummaryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shanshan.system.vo.NoticeVo;
import com.shanshan.system.vo.Result;
import com.sun.org.apache.regexp.internal.RE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author shanshan
 * @since 2023-01-31
 */
@Service
@SuppressWarnings("all")
public class MeetingSummaryServiceImpl extends ServiceImpl<MeetingSummaryMapper, MeetingSummary> implements IMeetingSummaryService {

    @Autowired
    private MeetingSummaryMapper meetingSummaryMapper;
    @Override
    public Result queryAllNotice(int currentPage, int pageSize, NoticeVo noticeVo) {
        QueryWrapper<MeetingSummary> wrapper = new QueryWrapper<>();
        if(noticeVo.getDate()!=null){
            noticeVo.setStartDate(noticeVo.getDate()[0]);
            noticeVo.setEndDate(noticeVo.getDate()[1]);
            wrapper.between("time",noticeVo.getStartDate(),noticeVo.getEndDate());
        }

        if (noticeVo.getTitle()!=null){
            wrapper.like("title",noticeVo.getTitle());
        }
        PageHelper.startPage(currentPage,pageSize);
        List<MeetingSummary> list = meetingSummaryMapper.selectList(wrapper);
        PageInfo<MeetingSummary> pageInfo = new PageInfo<>(list);
        return new Result(200,"查询成功",pageInfo);
    }

    @Override
    public Result addMeetingSummary(MeetingSummary meetingSummary) {
        meetingSummary.setTime(LocalDateTime.now());
        int insert = meetingSummaryMapper.insert(meetingSummary);
        if (insert==1){
            return new Result(200,"添加成功");
        }
        return new Result(500,"添加失败");
    }
}
